It shows how to import/export camera feature tree files. The major steps include exporting camera attributes to a file (such as FeatureFile.ini) by calling MV_CC_FeatureSave(), and importing camera feature tree from a file (such as FeatureFile.ini) by calling MV_CC_FeatureLoad().
9 currentsystem = platform.system()
10 if currentsystem ==
'Windows':
11 sys.path.append(os.path.join(os.getenv(
'MVCAM_COMMON_RUNENV'),
"Samples",
"Python",
"MvImport"))
13 sys.path.append(os.path.join(
"..",
"..",
"MvImport"))
14 from MvCameraControl_class
import *
17 if sys.version_info[0] < 3:
19 input_func = raw_input
27 Safely decode a string from a ctypes character array. 28 Compatible with Python 2.x and 3.x, as well as 32-bit and 64-bit environments. 30 byte_str = memoryview(ctypes_char_array).tobytes()
33 null_index = byte_str.find(b
'\x00')
35 byte_str = byte_str[:null_index]
38 for encoding
in [
'gbk',
'utf-8',
'latin-1']:
40 return byte_str.decode(encoding)
41 except UnicodeDecodeError:
45 return byte_str.decode(
'latin-1', errors=
'replace')
49 if __name__ ==
"__main__":
53 MvCamera.MV_CC_Initialize()
55 SDKVersion = MvCamera.MV_CC_GetSDKVersion()
56 print (
"SDKVersion[0x%x]" % SDKVersion)
58 deviceList = MV_CC_DEVICE_INFO_LIST()
59 tlayerType = MV_GIGE_DEVICE | MV_USB_DEVICE
62 ret = MvCamera.MV_CC_EnumDevices(tlayerType, deviceList)
64 print (
"enum devices fail! ret[0x%x]" % ret)
67 if deviceList.nDeviceNum == 0:
68 print (
"find no device!")
71 print (
"find %d devices!" % deviceList.nDeviceNum)
73 for i
in range(0, deviceList.nDeviceNum):
74 mvcc_dev_info = cast(deviceList.pDeviceInfo[i], POINTER(MV_CC_DEVICE_INFO)).contents
75 if mvcc_dev_info.nTLayerType == MV_GIGE_DEVICE :
76 print (
"\ngige device: [%d]" % i)
77 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stGigEInfo.chModelName)
78 print (
"device model name: %s" % strModeName)
79 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stGigEInfo.chSerialNumber)
80 print(
"device serial number: %s" % strSerialNumber)
81 nip1 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24)
82 nip2 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16)
83 nip3 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8)
84 nip4 = (mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff)
85 print (
"current ip: %d.%d.%d.%d\n" % (nip1, nip2, nip3, nip4))
86 elif mvcc_dev_info.nTLayerType == MV_USB_DEVICE:
87 print (
"\nu3v device: [%d]" % i)
88 strModeName =
decoding_char(mvcc_dev_info.SpecialInfo.stUsb3VInfo.chModelName)
89 print (
"device model name: %s" % strModeName)
91 strSerialNumber =
decoding_char(mvcc_dev_info.SpecialInfo.stUsb3VInfo.chSerialNumber)
92 print (
"device serial number: %s" % strSerialNumber)
94 nConnectionNum =
input_func(
"please input the number of the device to connect:")
96 if int(nConnectionNum) >= deviceList.nDeviceNum:
97 print (
"intput error!")
104 stDeviceList = cast(deviceList.pDeviceInfo[int(nConnectionNum)], POINTER(MV_CC_DEVICE_INFO)).contents
106 ret = cam.MV_CC_CreateHandle(stDeviceList)
108 raise Exception (
"create handle fail! ret[0x%x]" % ret)
111 ret = cam.MV_CC_OpenDevice(MV_ACCESS_Exclusive, 0)
113 raise Exception (
"open device fail! ret[0x%x]" % ret)
115 print (
"start export the camera properties to the file")
119 ret = cam.MV_CC_FeatureSave(
"FeatureFile.mfs")
121 raise Exception (
"save feature fail! ret [0x%x]" % ret)
122 print (
"finish export the camera properties to the file")
124 print (
"start import the camera properties from the file")
128 ret = cam.MV_CC_FeatureLoad(
"FeatureFile.mfs")
130 raise Exception (
"load feature fail! ret [0x%x]" % ret)
131 print (
"finish import the camera properties from the file")
134 ret = cam.MV_CC_CloseDevice()
136 raise Exception (
"close deivce fail! ret[0x%x]" % ret)
139 cam.MV_CC_DestroyHandle()
141 except Exception
as e:
143 cam.MV_CC_CloseDevice()
144 cam.MV_CC_DestroyHandle()
147 MvCamera.MV_CC_Finalize()